package com.ultrapower.ctool.xn_app;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.ultrapower.ctool.core.CustomApplication;
import com.ultrapower.ctool.http.ActivityCollector;
import com.ultrapower.ctool.http.BaseActivity;
import com.ultrapower.ctool.utils.SerializableMap;

import java.util.Map;

public class SystemOtherActivity extends BaseActivity implements View.OnClickListener {
    private TextView addUserButton;

    private TextView changePwdButton;

    private TextView logoutButton;
    private String userInfo;
    private TextView exitButton;
    private CustomApplication application;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_other);
        init();
        application = (CustomApplication) getApplication();
        userInfo = application.getLoginUser().getLogin_id();
        //TextView lblTitle = (TextView) findViewById(R.id.username_top);
        //lblTitle.getText();
        //lblTitle.setText((userInfo == null ? "" : userInfo) + lblTitle.getText());
    }

    private void init() {
        addUserButton = (TextView) findViewById(R.id.addUserButton);
        changePwdButton = (TextView) findViewById(R.id.changePasswordButton);
        logoutButton = (TextView) findViewById(R.id.logoutButton);
        exitButton = (TextView) findViewById(R.id.exitSysButton);
        addUserButton.setOnClickListener(this);
        changePwdButton.setOnClickListener(this);
        logoutButton.setOnClickListener(this);
        exitButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.addUserButton:
                Map menuMap=application.getSerializableMap().getMap();
                if(menuMap.containsKey("m_user_add")) {
                    Intent intent1 = new Intent(SystemOtherActivity.this, RegisterActivity.class);
                    startActivity(intent1);
                }else{
                    Toast.makeText(this, "没有相关权限", Toast.LENGTH_SHORT).show();
                }



                break;
            case R.id.changePasswordButton:
                Intent intent2 = new Intent(SystemOtherActivity.this, ChangePasswordActivity.class);
                startActivity(intent2);
                break;
            case R.id.logoutButton:
                Intent logoutIntent = new Intent(SystemOtherActivity.this, LoginActivity.class);
                logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(logoutIntent);
                break;
            case R.id.exitSysButton:
                android.os.Process.killProcess(android.os.Process.myPid());
                System.exit(0);
                break;
        }
    }
}
